package game;

import java.awt.*;
import java.awt.geom.Point2D;
import java.applet.*;
import java.net.*;
//import java.util.Vector;

abstract class GameObject
{
	private Image image;
	private Point2D position;
	private Point2D dimension;
	private Rectangle rectangle;
	public SoundClip sound;
	
	public GameObject(Point2D position, Point2D size, 
			SoundClip soundclip)
	{
		this.position  = position;
		this.dimension = size;
		this.sound = soundclip;
	}

	public Image getImage() {
		return image;
	}

	public void setImage(Image image) {
		this.image = image;
	}

	public Point2D getPosition() {
		return position;
	}

	public void setPosition(Point2D position) {
		this.position = position;
	}

	public Point2D getDimension() {
		return dimension;
	}

	public void setDimension(Point2D dimension) {
		this.dimension = dimension;
	}

	protected URL getURL(String filename)
	{
		URL url = null;
		try
		{
			url = this.getClass().getResource(filename);
		}
		catch (Exception e) { }
		return url;
	}

	public void load(String filename)
	{
		Toolkit tk = Toolkit.getDefaultToolkit();

		image = tk.getImage(getURL(filename));
	}

	public  void update()
	{
		
	}

	public void draw(Graphics g)
	{
		g.drawImage(image, (int)this.position.getX(), (int)this.position.getY(), 
				(int)this.dimension.getX(), (int)this.dimension.getY(), null);
	}
	


	public boolean collision(GameObject object)
	{
		return this.rectangle.intersects(object.rectangle);
				
/*		return (this.x < object.x + object.w &&
				this.x + this.w > object.x   &&
				this.y < object.y + object.h &&
				this.y + this.h > object.y   );*/
	}
}
